package com.cxm.support.controller;


import com.cxm.support.entity.Chart;
import com.cxm.support.entity.User;
import com.cxm.support.service.ChartService;

import com.cxm.support.vo.DataVO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpSession;
import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cxm
 * @since 2022-05-13
 */
@Controller
@RequestMapping("/support")
public class ChartController {
    @Autowired
    private ChartService chartService;

    @GetMapping("/workchartlistdata")
    @ResponseBody
    @RequiresPermissions("完工权限")
    public DataVO redirect7(Integer page, Integer limit) {
        return chartService.findWorkData(page, limit);
    }


    @GetMapping("/waitchartlistdata")
    @ResponseBody
    @RequiresPermissions("审核权限")
    public DataVO redirect4(Integer page, Integer limit) {
        return chartService.findWaitData(page, limit);
    }

    @GetMapping("/chartlistdata")
    @ResponseBody
    public DataVO redirect3(Integer page, Integer limit) {
        return chartService.findData(page, limit);
    }

    @PostMapping("/chartlistadd")
    @ResponseBody
    public String chartlistadd(Chart chart) {
        Subject subject= SecurityUtils.getSubject();
        User user = (User) subject.getSession().getAttribute("user");
        LocalDate date = LocalDate.now();
        chart.setPublishtime(date);
        chart.setStatus("待审核");
        chart.setAuthor(user.getUsername());
        chartService.save(chart);

        return null;
    }

    //    删除
    @PostMapping("/chartlistdelete")
    @ResponseBody

    public String lotteryDelete(Integer id) {

        chartService.removeById(id);
        return null;}

    @PostMapping("/changechartliststatuswan")
    @ResponseBody
    public String changestatus1(Integer id) {

        Chart chart = chartService.getById(id);
        chart.setStatus("已完工");
        chartService.updateById(chart);
        return null;}
    @PostMapping("/changechartliststatusshou")
    @ResponseBody
    public String changestatus2(Integer id) {

        Chart chart = chartService.getById(id);
        chart.setStatus("处理中");
        chartService.updateById(chart);
        return null;}
    @PostMapping("/changechartliststatustui")
    @ResponseBody
    public String changestatus3(Integer id) {

        Chart chart = chartService.getById(id);
        chart.setStatus("退回");
        chartService.updateById(chart);
        return null;}












    @PostMapping("/chartlistupdate")
    @ResponseBody
    public String lotteryUpdate(Chart chart) {
        LocalDate date = LocalDate.now();
        chart.setPublishtime(date);

        chartService.updateById(chart);
        return null;
    }




























    }

